#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    //SvgWidget *svgWidget = new SvgWidget(this);
    svgWidget = new SvgWidget(this);
    svgWidget->setSvgFile(":/Images/Images/ImageWolf3.svg");

    //setCentralWidget(svgWidget);
    QWidget *centralWidget = new QWidget(this);
    QVBoxLayout *layout = new QVBoxLayout(centralWidget);
    setWindowTitle("SVG Widget Example");

        radioButton1 = new QRadioButton("Image 1", this);
        radioButton2 = new QRadioButton("Image 2", this);
        radioButton3 = new QRadioButton("Image 3", this);
        radioButton4 = new QRadioButton("Image 4", this);

        layout->addWidget(radioButton1);
        layout->addWidget(radioButton2);
        layout->addWidget(radioButton3);
        layout->addWidget(radioButton4);
        layout->addWidget(svgWidget);

        setCentralWidget(centralWidget);

   /* radioButton1 = findChild<QRadioButton*>("radioButton1");
    radioButton2 = findChild<QRadioButton*>("radioButton2");
    radioButton3 = findChild<QRadioButton*>("radioButton3");
    radioButton4 = findChild<QRadioButton*>("radioButton4");*/

    connect(radioButton1, &QRadioButton::toggled, this, &MainWindow::onRadioButtonToggled);
    connect(radioButton2, &QRadioButton::toggled, this, &MainWindow::onRadioButtonToggled);
    connect(radioButton3, &QRadioButton::toggled, this, &MainWindow::onRadioButtonToggled);
    connect(radioButton4, &QRadioButton::toggled, this, &MainWindow::onRadioButtonToggled);

    radioButton1->setChecked(true);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::onRadioButtonToggled(bool checked)
{
    if(!checked) return;
    QRadioButton *senderButton = qobject_cast<QRadioButton*>(sender());

    if (senderButton == radioButton1 && radioButton1->isChecked())
    {
        svgWidget->setSvgFile(":/Images/Images/ImageWolf.svg");
    }
    else if(senderButton == radioButton2 && radioButton2->isChecked())
    {
         svgWidget->setSvgFile(":/Images/Images/ImageWolf2.svg");
    }
    else if(senderButton == radioButton3 && radioButton3->isChecked())
    {
         svgWidget->setSvgFile(":/Images/Images/ImageWolf3.svg");
    }
    else if(senderButton == radioButton4 && radioButton4->isChecked())
    {
         svgWidget->setSvgFile(":/Images/Images/ImageWolf4.svg");
    }
}
